package com.nhn.productmyself.lib;

import android.app.Dialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.text.TextUtils;

public class SimpleDialogFragment extends DialogFragment {
	
	public static final String TAG_DIALOG_ID = "tag_dialog_id";
	public static final String KEY_DIALOG_TITLE = "key_dialog_title";
	public static final String KEY_DIALOG_MESSAGE = "key_dialog_message";
	public static final String KEY_DIALOG_ICON = "key_dialog_icon";
	
	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		Dialog dialog = null;
		Builder builder = new Builder(getActivity());
		String tag = getTag();
		Bundle bundle = getArguments();
		if (tag.equals(TAG_DIALOG_ID)) {
			if (bundle.getInt(KEY_DIALOG_ICON, -1) != -1) {
				builder.setIcon(bundle.getInt(KEY_DIALOG_ICON));
			}
			if (!TextUtils.isEmpty(bundle.getString(KEY_DIALOG_TITLE))) {
				builder.setTitle(bundle.getString(KEY_DIALOG_TITLE));
			} else {
				builder.setTitle(null);
			}
			if (!TextUtils.isEmpty(bundle.getString(KEY_DIALOG_MESSAGE))) {
				builder.setMessage(bundle.getString(KEY_DIALOG_MESSAGE));
			} else {
				builder.setMessage(null);
			}
			builder.setPositiveButton("OK", new OnClickListener() {
				
				@Override
				public void onClick(DialogInterface dialog, int which) {
					dialog.cancel();
				}
			});
		}
		dialog = builder.create();
		return dialog;
	}
}
